const {Article} = require('../../model/article');
const pagination = require('mongoose-sex-page');

module.exports = async (req, res) => {
    //用户是否登录


    let page = req.query.page || 1;
    //多集合联合查询
    let result = await pagination(Article)
        .page(page).size(6).display(5).find().populate('author').exec();
    //渲染模板
    if ((page - 0) > (result.pages - 0)) {
        result = await pagination(Article)
            .page(1).size(6).display(5).find().populate('author').exec();
    }
    //res.send(result);
    res.render('home/default', {result});
};
